12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- "use client";
- import { AdItem } from "@/api/customservice";
- import { useRouter } from "@/i18n/routing";
- import { server } from "@/utils/client";
- import { useRequest } from "ahooks";
- import React from "react";
- import { Autoplay, Pagination } from "swiper/modules";
- import { Swiper, SwiperSlide } from "swiper/react";
- export const getLoginAdApi = async () => {
- return server
- .request<AdItem[]>({
- url: "/v1/api/front/activity_promotion_guests",
- method: "POST",
- })
- .then((res) => {
- return res.data;
- })
- .catch((err) => {
- return [];
- });
- };
- interface AdboxProps {
- // data: AdItem[];
- }
- const Adbox: React.FC<AdboxProps> = () => {
- const router = useRouter();
- const { data } = useRequest(getLoginAdApi);
- const doClick = async (data: AdItem) => {
- switch (data.action_type) {
- case 2:
- window.open(data.action_params, "_blank");
- break;
- case 3:
- let path = data.action_params;
- if (path) router.push(path);
- break;
- case 5:
- data?.action_params ? await eval(data?.action_params || "") : "";
- break;
- default:
- break;
- }
- };
- return (
- <div className="p-[.1rem]">
- <Swiper
- spaceBetween={10}
- autoplay
- modules={[Pagination, Autoplay]}
- pagination={{ clickable: true }}
- >
- {!!data?.length &&
- data.map((item) => {
- return (
- <SwiperSlide key={item.id} onClick={() => doClick(item)}>
- <img src={item.content} alt="" />
- </SwiperSlide>
- );
- })}
- </Swiper>
- </div>
- );
- };
- export default Adbox;
|